<template>
  <el-upload class="import__button" :action="importAction" :show-file-list="false" v-bind="$attrs" :on-success="handleSuccess">
    <el-button type="primary">{{buttonText}}</el-button>
  </el-upload>
</template>
<script>
import serverUrl from '@/config/url'
export default {
  name: 'aries-import',
  props: {
    tableName: { type: String, required: true },
    buttonText: { type: String, default: '导入' }
  },
  data () {
    return {
      importAction: `${serverUrl}/Web/SysAdmin/ajax.html?sys_method=Import&sys_objName=${this.tableName}&sys_tableName=${this.tableName}&UserID=${this.$store.state.app.userInfo.userid}`
    }
  },
  methods: {
    handleSuccess (resp) {
      if (!resp.success) {
        this.$message({ type: 'error', message: resp.msg })
      } else {
        this.$message({ type: 'success', message: resp.msg })
        this.$emit('on-success', resp)
      }
    }
  }
}
</script>
<style lang="less" scoped>
  .import__button {
    display: inline-block;
    margin-left: 10px;
  }
</style>
